package com.bigShen.spring.official;

/**
 * @Author eddy.shen
 * @Date 2019/1/20 11:45
 **/
public class SpringFlow {

    public static void main(String[] args) {

        // IOC 解析xml, scan扫描到的配置bean
        /**
         *
         *
         * IOC容器初始化: 分为三步:
         *  定位 : 定位资源文件
         *  加载 : 解析资源文件,将资源文件转换为BeanDefine
         *  注册 : 将BeanDefine存于DefaultListAbleBeanFactory的线程安全的map中
         *
         *
         FileSystemXmlApplicationContext -> AbstractXmlApplicationContext -> AbstractRefreshableConfigApplicationContext
         -> AbstractRefreshableApplicationContext -> AbstractApplicationContext ->
         定位 :
         1. 设置解析器:
         AbstractApplicationContext#resourcePatternResolver = new PathMatchingResourcePatternResolver(this)

         2. 设置资源文件路径:
         AbstractRefreshableConfigApplicationContext#configLocations = resolvePath(locations[i]).trim()


         载入/加载为BeanDefinitionHolder : 	扫描资源,转为Document, Element -> AbstractBeanDefinition -> BeanDefinitionHolder
         3. AbstractApplicationContext.obtainFreshBeanFactory
            -> AbstractRefreshableApplicationContext.createBeanFactory()
            -> AbstractXmlApplicationContext.loadBeanDefinitions()
                new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions()
                    -> XmlBeanDefinitionReader.doLoadBeanDefinitions
                        XmlBeanDefinitionReader.doLoadDocument(inputSource, resource)
                        -> DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions
                            DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(root, this.delegate)

                         -> DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource
                         | processAliasRegistration | 	processBeanDefinition | doRegisterBeanDefinitions
                             -> BeanDefinitionParserDelegate. parseBeanDefinitionAttributes
                             | parsePropertyElements ..

         注册
         4.								-> BeanDefinitionReaderUtils.registerBeanDefinition
         ->DefaultListableBeanFactory.registerBeanDefinition

         *
         *
         */

        /**
         *
         1. 定义资源解析器
         org.springframework.context.support.AbstractApplicationContext#getResourcePatternResolver()
         protected ResourcePatternResolver getResourcePatternResolver() {
         return new PathMatchingResourcePatternResolver(this);
         }

         2. 	设置资源文件路径
         org.springframework.context.support.AbstractRefreshableConfigApplicationContext#configLocations
         private String[] configLocations;

         3. 	beanDefineReader解析加载bean;
         org.springframework.beans.factory.support.AbstractBeanDefinitionReader#loadBeanDefinitions(java.lang.String...)
         org.springframework.beans.factory.xml.XmlBeanDefinitionReader#loadBeanDefinitions(org.springframework.core.io.support.EncodedResource)
         org.springframework.beans.factory.xml.XmlBeanDefinitionReader#doLoadBeanDefinitions(InputSource inputSource, Resource resource)


         3.1 将 resource资源文件转为 org.w3c.dom.Document
         org.springframework.beans.factory.xml.XmlBeanDefinitionReader#doLoadDocument
         3.2 解析document资源文件节点内容,
         org.springframework.beans.factory.xml.XmlBeanDefinitionReader#registerBeanDefinitions
         org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader#doRegisterBeanDefinitions
         将element节点转为BeanDefinitionHolder
         org.springframework.beans.factory.xml.BeanDefinitionParserDelegate#parseCustomElement(org.w3c.dom.Element)
         org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader#parseDefaultElement
         3.3 将BeanDefinitionHolder注册进入BeanFactory容器
         org.springframework.beans.factory.support.BeanDefinitionReaderUtils#registerBeanDefinition
         org.springframework.beans.factory.support.BeanDefinitionRegistry#registerBeanDefinition
         org.springframework.beans.factory.support.DefaultListableBeanFactory#registerBeanDefinition



         StringResourceLocation -> Document -> Element -> BeanDefinitionHolder ->
         -> BeanDefine(RootBeanDefine, ScannedGenericBeanDefinition, GenericBeanDefinition)

         */

    }


    void c2(){
        // DI 静态rootBeanDefine对象创建, 属性注入
        /**
         *
         *

         org.springframework.beans.factory.support
         .DefaultListableBeanFactory#getBean(java.lang.Class<T>)

         org.springframework.beans.factory.support
         .AbstractBeanFactory#doGetBean

         org.springframework.beans.factory.support
         .AbstractBeanFactory#createBean

         org.springframework.beans.factory.support
         .AbstractAutowireCapableBeanFactory#createBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[])

         org.springframework.beans.factory.support
         .AbstractAutowireCapableBeanFactory#doCreateBean
         AbstractAutowireCapableBeanFactory#createBeanInstance
         AbstractAutowireCapableBeanFactory#populateBean


         *
         */

    }

}
